/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test.alan.hyperblobs;

import java.util.*;

/**
 * Continually does physics simulation and game-state updating.
 *
 * @author Michael Zhang
 */
public class LevelUpdater extends Thread implements ILevelUpdates {

    /**
     *
     */
    private final LevelDrawer mDrawer;
    /**
     * Our data that will be continually updated. <br/> <b>Inconsistent</b>
     */
    private final Map<String, Object> mData;
    /**
     * Our physics updater.
     */
    private final LevelPhysicsUpdater mPhysics;

    /**
     *
     * @param drawer
     */
    public LevelUpdater(LevelDrawer drawer) {
        mData = new HashMap<String, Object>();
        mDrawer = drawer;
        mPhysics = new LevelPhysicsUpdater(9.8f, this, mData);

    }

    /**
     * Main physics loop.
     */
    @Override
    public void run() {
        mPhysics.run();
        mDrawer.setData(prepForRelease(mData));
    }

    public void onBlobDeath(BlobDeathCause cause) {
    }

    public void onBlobFinish() {
    }

    public void onBlobCollectStar() {
    }

    public void onBlobCollectPowerup(BlobPowerups powerup) {
    }

    //<editor-fold desc="Utility Methods">
    /**
     * Prepares the given map to be made public. Note: Typically a lengthy
     * operation.
     *
     * @param <K> The key type of the maps
     * @param <V> The value type of the maps
     * @param map The map to prepare
     * @return {@code Collections.unmodifiableMap(new HashMap<K, V>(map))}
     */
    private static <K, V> Map<K, V> prepForRelease(Map<? extends K, ? extends V> map) {
        return Collections.unmodifiableMap(new HashMap<K, V>(map));
    }
    //</editor-fold>
}
